/*
 * 主页功能
 * 
 */

//所有ajax加载完执行
$.when(indexAjax, cityPlugin, commodity).done(function () {

  "use strict"; //严格模式

  //搜索引擎
  var $loginbarTitle = $(".loginbar .title");
  var $iconsousuo = $(".loginbar .iconsousuo")
  var $iconxiangji = $(".loginbar .iconxiangji");
  var $loginbarInput = $("#loginbarInput");

  $(".searchTab").click(function () {
    //获取input焦点
    $loginbarInput.focus();

    $(this).addClass("selected").siblings().removeClass("selected");

    var $selectedHTML = $(".selected").html();
    if ($selectedHTML == "天猫" || $selectedHTML == "店铺") {
      $loginbarTitle.hide();
      $iconxiangji.hide();
    } else {
      if ($loginbarInput.val() == "") {
        $loginbarTitle.show();
      }
      $iconxiangji.show();
    }

  });

  // loginbarInput 事件监听
  $loginbarInput.bind('input porpertychange', function () {

    if ($loginbarInput.val() != "") {
      $loginbarTitle.hide();
      $iconsousuo.hide();
    } else {
      if ($(".selected").html() == "宝贝") {
        $loginbarTitle.show();
      }
      $iconsousuo.show();
    }

  })

  //搜索推荐
  var $searchBottomLines = $("#search-bottom-lines");
  var searchBottomLinesLenght = $("#search-bottom-lines div").length;
  var searchBottomLinesDiv = $("#search-bottom-lines div").height();
  //给运动函数赋值
  var searchBottomLines = new upward($searchBottomLines, searchBottomLinesLenght, searchBottomLinesDiv, 10000);
  //自动轮播
  searchBottomLines.autoMove(searchBottomLines);

  //手机淘宝二维码
  $(".mobileTaobao-close").click(function () {
    $(".mobileTaobao").hide();
  })

  //classification
  var $classification = $('#classification');
  var $serviceFloat = $('#service-float');
  var $serviceLi = $('#service li');

  //外层
  $classification.mouseleave(function () {
    $serviceFloat.stop().fadeOut();
  });

  //对应的li显示对应的div
  $serviceLi.mouseenter(function () {
    $serviceFloat.stop().fadeIn();
    var $index = $(this).index();
    $serviceFloat.find(".box").eq($index).show().siblings().hide();
  });

  //轮播
  //promo
  var $promoPrev = $("#promo #prev");
  var $promoNext = $("#promo #next");
  var $promoImg = $("#promo .promo-img");
  var $promoLi = $("#promo .promo-nav li");
  var promoNum = $promoLi.length; //最大个数就是标点个数
  var promoWidth = $("#promo .promo-img a").width();
  //给运动函数赋值
  var promo = new Frame($promoImg, $promoLi, promoNum, promoWidth, 5000);
  //自动轮播
  promo.autoMove(promo);
  //下一页
  $promoNext.click(function () {
    promo.next();
  });
  //上一页
  $promoPrev.click(function () {
    promo.prev();
  });
  //标点
  $promoLi.click(function () {
    promo.index = $(this).index();
    promo.core();
  });
  //鼠标移入移出
  $("#promo").mouseover(function () {
    clearInterval(promo.counter);
  }).mouseout(function () {
    promo.autoMove(promo);
  });

  //tmall
  var $tmallPrev = $("#tmall #prev");
  var $tmallNext = $("#tmall #next");
  var $tmallImg = $("#tmall .tmall-img");
  var $tmallLi = $("#tmall .tmall-nav li");
  var tmallNum = $tmallLi.length;
  var tmallWidth = $("#tmall .tmall-img div").width();
  var $currentPage = $("#currentPage");
  var $pageCount = $("#pageCount");
  $pageCount.html(tmallNum);
  //给运动函数赋值
  var tmall = new Frame($tmallImg, $tmallLi, tmallNum, tmallWidth, 5000);
  //当前页数
  tmall.currentPage(tmall, $currentPage);
  //自动轮播
  tmall.autoMove(tmall);
  //下一页
  $tmallNext.click(function () {
    tmall.next();
  });
  //上一页
  $tmallPrev.click(function () {
    tmall.prev();
  });
  //标点
  $tmallLi.click(function () {
    tmall.index = $(this).index();
    tmall.core();
  });
  //鼠标移入移出
  $("#tmall").mouseover(function () {
    clearInterval(tmall.counter);
  }).mouseout(function () {
    tmall.autoMove(tmall);
  });

  //淘宝头条
  var $headlineBdBox = $("#headline-bd-box");
  var headlineBdBoxLength = $("#headline-bd-box li").length;
  var headlineBdBoxLi = $("#headline-bd-box li").height();
  //给运动函数赋值
  var headlineBdBox = new upward($headlineBdBox, headlineBdBoxLength, headlineBdBoxLi, 5000);
  //自动轮播
  headlineBdBox.autoMove(headlineBdBox);

  //notice 选项卡
  var $noticeHdLi = $("#notice-hd li");
  var $noticeBdUl = $("#notice-bd ul");
  var noticeTimer = null;

  $noticeHdLi.mouseenter(function () {
    var this_ = this;
    noticeTimer = setTimeout(function () {
      $(this_).addClass("selected").siblings().removeClass("selected");
      $noticeBdUl.eq($(this_).index()).show().siblings().hide();
    }, 500);
  });
  $noticeHdLi.mouseleave(function () {
    clearTimeout(noticeTimer);
  });

  //conve
  var $conveList = $('.conve .conve-list .mouseleave');
  var $conveBdBox = $('.conve .conve-bd-box');
  var $conveBdItem = $(".conve .conve-bd-box-tab .conve-bd-item")
  var $conveBdBoxClose = $(".conve .conve-bd-box .conve-bd-box-close");

  $conveList.mouseenter(function () {
    $(this).addClass("selected").siblings().removeClass("selected");
    $conveBdBox.show();
    $conveBdItem.eq($(this).index()).show().siblings().hide();
    $(document).click();
  });

  $conveBdBoxClose.click(function () {
    $conveBdBox.hide();
    $conveList.removeClass("selected");
  });

  /*J_Conve_phone*/
  var $phoneNumberInput = $("#phoneNumberInput");
  var $phoneNumberdisplay = $("#phoneNumberdisplay");
  var $phoneNumberLog = $("#phoneNumberLog");
  var $conveInputIcontongxunlu = $("#conveInputIcontongxunlu");
  var $tbrPhoneDenom = $(".tbr-phone-denom");
  var $phoneDenomLog = $("#phoneDenomLog");
  var $phoneDenomInput = $("#phoneDenomInput");
  var $tbrPhonePrice = $("#tbrPhonePrice");
  var $phoneConveTabs = $(".J_Conve_phone .conve-tabs a");
  var $phoneBody = $(".J_Conve_phone .recharge-tab-body");
  var $tbrPhoneBtn = $("#tbrPhoneBtn");
  var phoneTimer = null;

  //phoneConveTabs选项卡
  $phoneConveTabs.mouseenter(function () {
    var this_ = this;
    phoneTimer = setTimeout(function () {
      $(this_).addClass("selected").siblings().removeClass("selected");
      $phoneBody.stop().animate({
        left: ($(this_).index() * -273) + 'px'
      }, 200);
      //让下面显示的消失
      $(document).click();
    }, 300)
  });
  $phoneConveTabs.mouseleave(function () {
    clearTimeout(phoneTimer);
  });

  /*话费充值*/
  //phoneNumberInput输入监听
  $phoneNumberInput.bind('input porpertychange', function () {

    $(this).val($(this).val().replace(/[^\d]/g, '')); //判断只能输入数字

    var phoneNumberInputValue = $(this).val();
    var phoneNumber = "";
    var phoneNumber1 = "";
    var phoneNumber2 = "";
    var phoneNumber3 = "";

    if (phoneNumberInputValue == "" || phoneNumberInputValue.length == "11") {
      $phoneNumberdisplay.hide();
      $phoneNumberLog.hide();
    } else {
      $phoneNumberdisplay.show();
    }

    if (phoneNumberInputValue[0]) {
      phoneNumber1 = phoneNumberInputValue.slice(0, 3);
    }
    if (phoneNumberInputValue[2]) {
      phoneNumber2 = "-" + phoneNumberInputValue.slice(3, 7);
    }
    if (phoneNumberInputValue[7]) {
      phoneNumber3 = "-" + phoneNumberInputValue.slice(7, 16);
    }
    phoneNumber = phoneNumber1 + phoneNumber2 + phoneNumber3;

    $phoneNumberdisplay.html(phoneNumber);

    $phoneNumberInput.click(function (e) {
      e.stopPropagation(); //禁止冒泡
      if (phoneNumberInputValue == "") {
        $phoneNumberdisplay.hide();
      } else {
        $phoneNumberdisplay.show();
      }
      //phoneDenomLog也跟着隐藏
      $phoneDenomLog.hide();
    });

  });
  //充值记录
  $conveInputIcontongxunlu.click(function (e) {
    phoneNumberLog("您还没有充记录", e);
  });
  //充值额度
  $phoneDenomInput.val($phoneDenomLog.find(".selected").html()); //默认额度
  $tbrPhonePrice.html("49-49.8");
  $tbrPhoneDenom.click(function (e) {
    //如果他隐藏，那么就显示
    if ($phoneDenomLog.is(':hidden')) {
      $phoneDenomLog.show();
    } else {
      $phoneDenomLog.hide();
    }
    e.stopPropagation();
  });
  $("#phoneDenomLog [data-value]").each(function (i, item) {
    $(this).click(function () {

      $phoneDenomInput.val($(this).attr("data-value"))
      $(this).addClass("selected").siblings().removeClass("selected");
      //判断渲染价格
      switch ($phoneDenomInput.val()) {
        case '100元':
          $tbrPhonePrice.html("98-99.5");
          break;
        case '10元':
          $tbrPhonePrice.html("9.8-9.9");
          break;
        case '200元':
          $tbrPhonePrice.html("196-199");
          break;
        case '20元':
          $tbrPhonePrice.html("19.6-20");
          break;
        case '300元':
          $tbrPhonePrice.html("294-299");
          break;
        case '30元':
          $tbrPhonePrice.html("29.4-30");
          break;
        case '500元':
          $tbrPhonePrice.html("490-498");
          break;
        case '50元':
          $tbrPhonePrice.html("49-49.8");
          break;
        case '1000元':
          $tbrPhonePrice.html("980-990");
          break;
      }

    });
  });
  //充值按钮
  $tbrPhoneBtn.click(function (e) {
    if ($phoneNumberInput.val() == "") {
      phoneNumberLog("请输入号码", e);
      $phoneNumberInput.focus();
    } else if ($phoneNumberInput.val().length < "11") {
      phoneNumberLog("请输入正确的号码", e);
      $phoneNumberInput.focus();
    } else {
      alert("充值成功！");
      $phoneNumberInput.val('');
      $phoneNumberdisplay.html('');
      $phoneNumberdisplay.hide();
    }
  });
  //phoneNumberLog赋值
  function phoneNumberLog(prompt, e) {
    $phoneNumberLog.html(prompt);
    $phoneNumberLog.show();
    $phoneNumberdisplay.hide();
    e.stopPropagation(); //禁止冒泡
  }

  /*流量充值*/
  var $flowNumberInput = $("#flowNumberInput");
  var $flowNumberdisplay = $("#flowNumberdisplay");
  var $flowNumberLog = $("#flowNumberLog");
  var $flowInputIcontongxunlu = $("#flowInputIcontongxunlu");
  var $flowArea = $("#flowArea");
  var $flowAreaInput = $("#flowArea input");
  var $phoneAreaLog = $("#phoneAreaLog");
  var $flowHowMany = $("#flowHowMany");
  var $flowHowManyInput = $("#howManyInput");
  var $phoneHowManyLog = $("#phoneHowManyLog");
  var $tbrFlowPrice = $("#tbrFlowPrice");
  var $flowDetails = $("#flowDetails");
  var $flowDetailsLog = $("#flowDetailsLog");
  var $tbrFlowBtn = $("#tbrFlowBtn");

  //flowNumberInput输入监听
  $flowNumberInput.bind('input porpertychange', function () {

    $(this).val($(this).val().replace(/[^\d]/g, '')); //判断只能输入数字

    var flowNumberInputValue = $(this).val();
    var phoneNumber = "";
    var phoneNumber1 = "";
    var phoneNumber2 = "";
    var phoneNumber3 = "";

    if (flowNumberInputValue == "" || flowNumberInputValue.length == "11") {
      $flowNumberdisplay.hide();
      Amount();
    } else {
      $flowNumberdisplay.show();
    }

    if (flowNumberInputValue[0]) {
      phoneNumber1 = flowNumberInputValue.slice(0, 3);
    }
    if (flowNumberInputValue[2]) {
      phoneNumber2 = "-" + flowNumberInputValue.slice(3, 7);
    }
    if (flowNumberInputValue[7]) {
      phoneNumber3 = "-" + flowNumberInputValue.slice(7, 16);
    }
    phoneNumber = phoneNumber1 + phoneNumber2 + phoneNumber3;
    $flowNumberdisplay.html(phoneNumber);

    $flowNumberInput.click(function (e) {
      e.stopPropagation(); //禁止冒泡
      if (flowNumberInputValue == "") {
        $flowNumberdisplay.hide();
      } else {
        $flowNumberdisplay.show();
      }
      //其他内容隐藏
      $phoneAreaLog.hide();
      $phoneHowManyLog.hide();
    });
  });
  //充值记录
  $flowInputIcontongxunlu.click(function (e) {
    $flowNumberLog.show();
    e.stopPropagation(); //禁止冒泡
    //其他内容隐藏
    $phoneAreaLog.hide();
    $phoneHowManyLog.hide();
  });
  //地区
  $flowArea.click(function (e) {
    //如果他隐藏，那么就显示
    if ($phoneAreaLog.is(':hidden')) {
      $phoneAreaLog.show();
      $phoneHowManyLog.hide();
    } else {
      $phoneAreaLog.hide();
    }
    e.stopPropagation();
  });
  $("#phoneAreaLog [data-value]").each(function (i, item) {
    $(this).click(function () {
      $flowAreaInput.val($(this).attr("data-value"))
      $(this).addClass("selected").siblings().removeClass("selected");
    });
  });
  //额度
  $flowHowMany.click(function (e) {
    //如果他隐藏，那么就显示
    if ($phoneHowManyLog.is(':hidden')) {
      $phoneHowManyLog.show();
      $phoneAreaLog.hide();
    } else {
      $phoneHowManyLog.hide();
    }
    e.stopPropagation();
  });
  $("#phoneHowManyLog [data-value]").each(function (i, item) {
    $(this).click(function () {
      $(this).addClass("selected").siblings().removeClass("selected");
      //判断渲染价格
      Amount()
    });
  });
  //判断渲染价格
  function Amount() {
    $flowHowManyInput.val($phoneHowManyLog.find(".selected").html());
    switch ($flowHowManyInput.val()) {
      case '1000M':
        $tbrFlowPrice.html("售价<span>￥</span><strong>27</strong>");
        break;
      case '2000M':
        $tbrFlowPrice.html("售价<span>￥</span><strong>40</strong>");
        break;
      case '3000M':
        $tbrFlowPrice.html("售价<span>￥</span><strong>56</strong>");
        break;
      case '4000M':
        $tbrFlowPrice.html("售价<span>￥</span><strong>80</strong>");
        break;
      case '10000M':
        $tbrFlowPrice.html("售价<span>￥</span><strong>120</strong>");
        break;
    }
  }
  Amount();
  //详情
  $flowDetails.hover(function () {
    $flowDetailsLog.show();
  }, function () {
    $flowDetailsLog.hide();
  });
  //流量充值
  $tbrFlowBtn.click(function () {
    if ($flowNumberInput.val() == '' || $flowNumberInput.val().length < "11") {
      $tbrFlowPrice.html('<p style="color: #F40">请输入正确的手机号码!</p>');
      $flowNumberInput.focus();
      var num = 0,
        index = 0,
        timer = null;
      timer = setInterval(function () {
        if (num == 0) {
          $tbrFlowPrice.find("p").css({
            "color": "#000",
            "fontWeight": "600"
          });
          num = 1;
        } else {
          $tbrFlowPrice.find("p").css({
            "color": "#F40",
            "fontWeight": "400"
          });
          num = 0;
        }
        index++
        if (index == 6) {
          clearInterval(timer);
        }
      }, 450);
    } else if ($flowNumberInput.val().length == "11") {
      alert("充值成功！");
      $flowNumberInput.val('');
    }
  });

  /*固话充值*/
  var $fixedlineFormIcontongxunlu = $("#fixedlineFormIcontongxunlu");
  var $fixedlineNumberLog = $("#fixedlineNumberLog");
  var $fixedlineAreacode = $("#fixedlineAreacode");
  var $fixedlineNumber = $("#fixedlineNumber");
  var $fixedlineError = $("#fixedlineError");
  var $fixedlineAmount = $("#fixedlineAmount");
  var $fixedlineLog = $("#fixedlineLog");
  var $AmountInput = $("#AmountInput");
  var $fixedlinePrice = $("#fixedlinePrice");
  var $fixedlineBtn = $("#fixedlineBtn");

  //区号
  $fixedlineAreacode.bind('input porpertychange', function () {
    $(this).val($(this).val().replace(/[^\d]/g, '')); //判断只能输入数字

    var areacodValue = $(this).val();
    if ($(this).val().length == 4) {
      $fixedlineNumber.focus(); //号码获取焦点
      $fixedlineError.hide();
    } else if ($(this).val().length > 4) {
      $(this).val(areacodValue.substr(0, areacodValue.length - 1)); //删除最后一个
      $fixedlineNumber.focus();
    }
  });

  //号码
  $fixedlineNumber.bind('input porpertychange', function () {
    if ($(this).val().length == 8) {
      $fixedlineError.hide();
    } else if ($(this).val().length == 0) {
      $fixedlineAreacode.focus();
    }
  });
  $fixedlineNumber.keydown(function (e) {
    if (e.keyCode == 8) {
      if ($(this).val().length == 0) {
        $fixedlineAreacode.focus();
        return false;
      }
    }
  });

  //错误提示
  $fixedlineError.click(function () {
    if ($(this).is(":hidden")) {
      $fixedlineError.show();
    } else {
      $fixedlineError.hide();
    }
  });

  $fixedlineAreacode.blur(function () {
    if ($(this).val().length == 1 || $(this).val().length == 2 || $(this).val().length == 3) {
      FixedlineError("区号对应的城市不存在")
    } else if ($(this).val().length == 0) {
      FixedlineError("请输入区号")
    }
  });

  $fixedlineNumber.blur(function () {
    if ($(this).val().length < 8) {
      FixedlineError("固话号码为7~8位数字")
    }
  });

  function FixedlineError(information) {
    $fixedlineError.html(information);
    $fixedlineError.show();
  }

  //充值记录
  $fixedlineFormIcontongxunlu.click(function (e) {
    $fixedlineNumberLog.show();
    $fixedlineError.hide();
    e.stopPropagation(); //禁止冒泡
  });

  //额度
  $AmountInput.val($fixedlineLog.find(".selected").html()); //默认额度
  $fixedlinePrice.html("售价<span>￥</span><strong>49.5 - 50</strong>");

  $fixedlineAmount.click(function (e) {
    if ($fixedlineLog.is(':hidden')) {
      $fixedlineLog.show();
      $(this).find("span").css('background-position', ' 0 0');
    } else {
      $fixedlineLog.hide();
      $(this).find("span").css('background-position', ' 0 -15px');
    }
    e.stopPropagation();
  });
  $("#fixedlineLog [data-value]").each(function (i, item) {
    $(this).click(function () {

      $(this).addClass("selected").siblings().removeClass("selected");
      $AmountInput.val($fixedlineLog.find(".selected").html());
      //判断渲染价格
      switch ($AmountInput.val()) {
        case '100元':
          $fixedlinePrice.html("售价<span>￥</span><strong>99 - 100</strong>");
          break;
        case '10元':
          $fixedlinePrice.html("售价<span>￥</span><strong>9.9 - 10</strong>");
          break;
        case '200元':
          $fixedlinePrice.html("售价<span>￥</span><strong>192 - 200</strong>");
          break;
        case '20元':
          $fixedlinePrice.html("售价<span>￥</span><strong>19.8 - 20</strong>");
          break;
        case '300元':
          $fixedlinePrice.html("售价<span>￥</span><strong>297 - 300</strong>");
          break;
        case '30元':
          $fixedlinePrice.html("售价<span>￥</span><strong>29.7 - 30</strong>");
          break;
        case '500元':
          $fixedlinePrice.html("售价<span>￥</span><strong>494 - 500</strong>");
          break;
        case '50元':
          $fixedlinePrice.html("售价<span>￥</span><strong>49.5 - 50</strong>");
          break;
      }

    });
  });

  //充值
  $fixedlineBtn.click(function () {
    $fixedlineAreacode.blur();
    $fixedlineNumber.blur();
    if ($fixedlineAreacode.val().length == 4 && $fixedlineNumber.val().length == 8) {
      alert("充值完成！");
      $fixedlineAreacode.val("");
      $fixedlineNumber.val("");
    }
  });

  /*宽带充值*/
  var $broadbandArea = $("#broadbandArea");
  var $broadbandLog = $("#broadbandLog");
  var $broadbandError = $("#broadbandError");
  var $broadbandIcontongxunlu = $("#broadbandIcontongxunlu");
  var $broadbandNumberLog = $("#broadbandNumberLog");
  var $broadbandDoubt = $("#broadbandDoubt");
  var $broadbandDoubtLog = $("#broadbandDoubtLog");
  var $broadbandAmount = $("#broadbandAmount");
  var $broadbandAmountInput = $("#broadbandAmount input");
  var $broadbandPrice = $("#broadbandPrice");
  var $broadbandAmountLog = $("#broadbandAmountLog");
  var $broadbandBtn = $("#broadbandBtn");
  var $operator = $("#broadbandLog .broadband-log-operator span a");
  var $broadbandAreaInput = $("#broadbandArea input");
  var $cityItem = $("#broadbandLogArea div a");
  var $broadbandAccount = $("#broadbandAccount");
  var $numberError = $("#numberError");
  var operatorRecording = "电信";
  var ocityItemRecording = "城市";

  //地区
  $broadbandArea.click(function (e) {

    if ($broadbandLog.is(':hidden')) {
      $broadbandLog.show();
      $(this).find("span").css('background-position', ' 0 0');
    } else {
      $broadbandLog.hide();
      $(this).find("span").css('background-position', ' 0 -15px');
    }
    e.stopPropagation();
    $broadbandNumberLog.hide();
    $broadbandError.hide();

  });

  /*地区插件*/
  //运营商选择
  $operator.click(function (e) {
    operatorRecording = $(this).html();
    $broadbandAreaInput.val(operatorRecording + '/' + ocityItemRecording);
    $(this).addClass("selected").siblings().removeClass("selected");
    e.stopPropagation();
  });
  //地区选择
  $cityItem.click(function () {
    ocityItemRecording = $(this).html();
    $broadbandAreaInput.val(operatorRecording + '/' + ocityItemRecording);
  });

  //地区提示
  $broadbandError.click(function (e) {
    $(this).hide();
    e.stopPropagation();
  });
  //号码提示
  $numberError.click(function (e) {
    $(this).hide();
    e.stopPropagation();
  });

  //充值记录
  $broadbandIcontongxunlu.click(function (e) {
    $broadbandNumberLog.show();
    e.stopPropagation(); //禁止冒泡
    $numberError.hide();
    $broadbandAmountLog.hide();
  });

  //宽带问号
  $broadbandDoubt.hover(function () {
    $broadbandDoubtLog.show();
  }, function () {
    $broadbandDoubtLog.hide();
  });

  //宽带金额
  $broadbandAmountInput.val($broadbandAmountLog.find(".selected").html());
  $broadbandPrice.html("售价<span>￥</span><strong>49.5 - 50</strong>");

  $broadbandAmount.click(function (e) {
    if ($broadbandAmountLog.is(':hidden')) {
      $broadbandAmountLog.show();
      $(this).find("span").css('background-position', ' 0 0');
    } else {
      $broadbandAmountLog.hide();
      $(this).find("span").css('background-position', ' 0 -15px');
    }
    e.stopPropagation();
  });
  $("#broadbandAmountLog [data-value]").each(function (i, item) {
    $(this).click(function () {
      $(this).addClass("selected").siblings().removeClass("selected");
      $broadbandAmountInput.val($broadbandAmountLog.find(".selected").html());

      //判断渲染价格
      switch ($broadbandAmountInput.val()) {
        case '100元':
          $broadbandPrice.html("售价<span>￥</span><strong>99 - 100</strong>");
          break;
        case '10元':
          $broadbandPrice.html("售价<span>￥</span><strong>9.9 - 10</strong>");
          break;
        case '200元':
          $broadbandPrice.html("售价<span>￥</span><strong>192 - 200</strong>");
          break;
        case '20元':
          $broadbandPrice.html("售价<span>￥</span><strong>19.8 - 20</strong>");
          break;
        case '300元':
          $broadbandPrice.html("售价<span>￥</span><strong>297 - 300</strong>");
          break;
        case '30元':
          $broadbandPrice.html("售价<span>￥</span><strong>29.7 - 30</strong>");
          break;
        case '500元':
          $broadbandPrice.html("售价<span>￥</span><strong>494 - 500</strong>");
          break;
        case '50元':
          $broadbandPrice.html("售价<span>￥</span><strong>49.5 - 50</strong>");
          break;
      }
    });
  });

  //宽带充值   
  $broadbandBtn.click(function (e) {
    if (ocityItemRecording == "城市") {
      $broadbandError.show();
      $broadbandNumberLog.hide();
    } else if ($broadbandAccount.val() == '') {
      $numberError.show();
      $broadbandNumberLog.hide();
    } else {
      alert("充值完成！");
      $broadbandAreaInput.val("电信/城市");
      operatorRecording = "电信";
      ocityItemRecording = "城市";
      $broadbandAccount.val("");
    }
    e.stopPropagation();
  });

  /*J_Conve_trip*/

  var $tourismTabs = $(".J_Conve_trip .conve-tabs a");
  var $tourismBody = $(".J_Conve_trip .recharge-tab-body");
  var tripTimer = null;
  var date_judgment = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/;

  var $domesticCitySetOff = $('#domestic_citySetOff');
  var $domesticCityArrivals = $('#domestic_cityArrivals');
  var $domestic_dateSetOff = $('#domestic_dateSetOff');
  var $domestic_Btn = $("#domestic_Btn");

  var $international_citySetOff = $('#international_citySetOff');
  var $international_cityArrivals = $('#international_cityArrivals');
  var $international_dateSetOff = $('#international_dateSetOff');
  var $international_Btn = $("#international_Btn");

  var $stayInTheCity = $("#stayInTheCity");
  var $hotel_Btn = $("#hotel_Btn")
  var $hotelCheckIn = $("#hotelCheckIn");
  var $hotelDeparture = $("#hotelDeparture");

  var $holidayTicket_setoff = $('#holidayTicket_setoff');
  var $holidayTicket_arrivals = $("#holidayTicket_arrivals");
  var $holidayTicket_Btn = $("#holidayTicket_Btn");

  var $trainticket_setoff_c = $("#trainticket_setoff_c");
  var $trainticket_arrivals_c = $("#trainticket_arrivals_c");
  var $trainticket_setoff_d = $("#trainticket_setoff_d");
  var $trainticket_Btn = $("#trainticket_Btn");

  //功能选项卡
  $tourismTabs.mouseenter(function () {
    var this_ = $(this);
    tripTimer = setTimeout(function () {
      this_.addClass("selected").siblings().removeClass("selected");
      $tourismBody.animate({
        left: (this_.index() * -273) + 'px'
      }, 200);
      $(document).click();
    }, 300);
  });
  $tourismTabs.mouseleave(function () {
    clearTimeout(tripTimer);
  });

  //国内热门城市
  $domesticCitySetOff.kuCity();
  $domesticCityArrivals.kuCity();
  //国内机票查找
  $domestic_Btn.click(function (e) {

    if ($domesticCitySetOff.val() == '') {

      $domesticCitySetOff.focus();
      $domesticCitySetOff.attr('placeholder', '请选择城市');

    } else if ($domesticCityArrivals.val() == '') {

      $domesticCityArrivals.focus();
      $domesticCityArrivals.attr('placeholder', '请选择城市');

    } else if ($domestic_dateSetOff.val() == '') {

      $domestic_dateSetOff.click();
      $domestic_dateSetOff.attr('placeholder', '请选择日期');

    } else if ($domesticCitySetOff.val() == $domesticCityArrivals.val()) {

      alert("出发城市和到达城市不能相同!");
      $domesticCityArrivals.focus();

    } else if (!date_judgment.test($domestic_dateSetOff.val())) {

      alert("日期格式为：yyyy-mm-dd !");
      $domestic_dateSetOff.click();

    } else {

      alert('查找成功！');
      $domesticCitySetOff.attr('placeholder', '城市');
      $domesticCityArrivals.attr('placeholder', '城市');
      $domestic_dateSetOff.attr('placeholder', '日期');

    }

    e.stopPropagation();

  });

  //国际热门城市
  $international_citySetOff.kuCity();
  $international_cityArrivals.kuCity();
  //国际机票查找
  $international_Btn.click(function (e) {

    if ($international_citySetOff.val() == '') {

      $international_citySetOff.focus();
      $international_citySetOff.attr('placeholder', '请选择城市');

    } else if ($international_cityArrivals.val() == '') {

      $international_cityArrivals.focus();
      $international_cityArrivals.attr('placeholder', '请选择城市');

    } else if ($international_dateSetOff.val() == '') {

      $international_dateSetOff.click();
      $international_dateSetOff.attr('placeholder', '请选择日期');

    } else if ($international_citySetOff.val() == $international_cityArrivals.val()) {

      alert("出发城市和到达城市不能相同!");
      $international_cityArrivals.focus();

    } else if (!date_judgment.test($international_dateSetOff.val())) {

      alert("日期格式为：yyyy-mm-dd !");
      $international_dateSetOff.click();

    } else {

      alert('查找成功！');
      $international_citySetOff.attr('placeholder', '城市');
      $international_cityArrivals.attr('placeholder', '城市');
      $international_dateSetOff.attr('placeholder', '日期');

    }

    e.stopPropagation();
  });

  //酒店热门城市
  $stayInTheCity.kuCity();
  //酒店查找
  $hotel_Btn.click(function (e) {

    if ($stayInTheCity.val() == '') {

      $stayInTheCity.focus();
      $stayInTheCity.attr('placeholder', '请选择城市');

    } else if ($hotelCheckIn.val() == '') {

      $hotelCheckIn.click();
      $hotelCheckIn.attr('placeholder', '请选择日期');

    } else if ($hotelDeparture.val() == '') {

      $hotelDeparture.click();
      $hotelDeparture.attr('placeholder', '请选择日期');

    } else if (!date_judgment.test($hotelCheckIn.val())) {

      alert("日期格式为：yyyy-mm-dd !");
      $hotelCheckIn.click();

    } else if (!date_judgment.test($hotelDeparture.val())) {

      alert("日期格式为：yyyy-mm-dd !");
      $hotelDeparture.click();

    } else {

      alert('查找成功！');
      $stayInTheCity.attr('placeholder', '城市');
      $hotelCheckIn.attr('placeholder', '日期');
      $hotelDeparture.attr('placeholder', '日期');
    }

    e.stopPropagation();
  });

  //度假门票
  $holidayTicket_setoff.kuCity();
  $holidayTicket_arrivals.kuCity();
  //度假门票查找
  $holidayTicket_Btn.click(function (e) {

    if ($holidayTicket_setoff.val() == '') {

      $holidayTicket_setoff.focus();
      $holidayTicket_setoff.attr('placeholder', '请选择城市');

    } else if ($holidayTicket_arrivals.val() == '') {

      $holidayTicket_arrivals.focus();
      $holidayTicket_arrivals.attr('placeholder', '请选择城市');

    } else {

      alert("查找成功");
      $holidayTicket_setoff.attr('placeholder', '城市');
      $holidayTicket_arrivals.attr('placeholder', '城市');

    }

    e.stopPropagation();

  });

  //火车票
  $trainticket_setoff_c.kuCity();
  $trainticket_arrivals_c.kuCity();
  //火车票查找
  $trainticket_Btn.click(function (e) {

    if ($trainticket_setoff_c.val() == '') {

      $trainticket_setoff_c.focus();
      $trainticket_setoff_c.attr('placeholder', '请选择城市');

    } else if ($trainticket_arrivals_c.val() == '') {

      $trainticket_arrivals_c.focus();
      $trainticket_arrivals_c.attr('placeholder', '请选择城市');

    } else if ($trainticket_setoff_c.val() == $trainticket_arrivals_c.val()) {

      $trainticket_arrivals_c.focus();
      alert('出发城市和到达车站不能相同!');

    } else if ($trainticket_setoff_d.val() == '') {

      $trainticket_setoff_d.click();
      $trainticket_setoff_d.attr('placeholder', '请选择日期');

    } else if (!date_judgment.test($trainticket_setoff_d.val())) {

      alert("日期格式为：yyyy-mm-dd !");
      $trainticket_setoff_d.click();

    } else {

      alert('查找成功！');
      $trainticket_setoff_c.attr('placeholder', '城市');
      $trainticket_arrivals_c.attr('placeholder', '城市');
      $trainticket_setoff_d.attr('placeholder', '日期');

    }

    e.stopPropagation();
  });

  /*J_Conve_Insurance*/

  var $insuranceTabs = $(".J_Conve_Insurance .conve-tabs a");
  var $insuranceBody = $(".J_Conve_Insurance .recharge-tab-body");
  var insuranceTimer = null;

  //选项卡
  $insuranceTabs.mouseenter(function () {

    var this_ = $(this);
    insuranceTimer = setTimeout(function () {
      this_.addClass('selected').siblings().removeClass('selected');
      $insuranceBody.animate({
        left: (this_.index() * -273) + 'px'
      }, 200);
      $(document).click();
    }, 300);

  });
  $insuranceTabs.mouseleave(function () {
    clearTimeout(insuranceTimer);
  });

  /*车险*/
  var $carInsurance_city = $('#carInsurance_city');
  var $carInsurance_drop_1 = $('#carInsurance_drop_1');
  var $insuranceCompany = $('#insuranceCompany');
  var $carInsurance_drop_2 = $('#carInsurance_drop_2');
  var $insurance_Btn = $("#insurance_Btn");

  //默认
  $carInsurance_city.val($carInsurance_drop_1.find('.selected').html())
  $insuranceCompany.val($carInsurance_drop_2.find('.selected').html())

  $carInsurance_city.click(function (e) {

    if ($carInsurance_drop_1.is(':hidden')) {
      $carInsurance_drop_1.show();
      $carInsurance_drop_2.hide();
    } else {
      $carInsurance_drop_1.hide();
    }

    $carInsurance_drop_1.find('li').click(function () {
      $(this).addClass('selected').siblings().removeClass('selected');
      $carInsurance_city.val($(this).text());
    });

    e.stopPropagation();

  });

  //车险总类
  $insuranceCompany.click(function (e) {

    if ($carInsurance_drop_2.is(':hidden')) {
      $carInsurance_drop_2.show();
      $carInsurance_drop_1.hide();
    } else {
      $carInsurance_drop_2.hide();
    }

    $carInsurance_drop_2.find('li').click(function () {
      $(this).addClass('selected').siblings().removeClass('selected');
      $insuranceCompany.val($(this).text());
    });

    e.stopPropagation();

  });

  //立刻报价
  $insurance_Btn.click(function (e) {

    if ($carInsurance_city.val() == '请选择城市') {

      $carInsurance_city.click();

      var num = 0,
        index = 0,
        timer = null;
      timer = setInterval(function () {
        if (num == 0) {
          $carInsurance_city.css({
            "color": "#000",
            "fontWeight": "600"
          });
          num = 1;
        } else {
          $carInsurance_city.css({
            "color": "#333",
            "fontWeight": "400"
          });
          num = 0;
        }
        index++
        if (index == 6 || $carInsurance_drop_1.is(':hidden')) {
          clearInterval(timer);
          $carInsurance_city.css({
            "color": "#333",
            "fontWeight": "400"
          });
        }
      }, 450);

    } else {
      alert($carInsurance_city.val() + ' + ' + $insuranceCompany.val());
    }

    e.stopPropagation();

  });

  /*意外险*/
  var $accidentInsurance_type = $('#accidentInsurance_type');
  var $accidentInsurance_drop_1 = $('#accidentInsurance_drop_1');
  var $accidentInsurance_time = $('#accidentInsurance_time');
  var $accidentInsurance_drop_2 = $('#accidentInsurance_drop_2');
  var $accidentInsurance_Btn = $("#accidentInsurance_Btn");

  //默认
  $accidentInsurance_type.val($accidentInsurance_drop_1.find('.selected').html())
  $accidentInsurance_time.val($accidentInsurance_drop_2.find('.selected').html())

  //意外险类型
  $accidentInsurance_type.click(function (e) {

    if ($accidentInsurance_drop_1.is(':hidden')) {
      $accidentInsurance_drop_1.show();
      $accidentInsurance_drop_2.hide();
    } else {
      $accidentInsurance_drop_1.hide();
    }

    $accidentInsurance_drop_1.find('li').click(function () {
      $(this).addClass('selected').siblings().removeClass('selected');
      $accidentInsurance_type.val($(this).text());
    });

    e.stopPropagation();

  });

  //意外险时间
  $accidentInsurance_time.click(function (e) {

    if ($accidentInsurance_drop_2.is(':hidden')) {
      $accidentInsurance_drop_2.show();
      $carInsurance_drop_1.hide();
    } else {
      $accidentInsurance_drop_2.hide();
    }

    $accidentInsurance_drop_2.find('li').click(function () {
      $(this).addClass('selected').siblings().removeClass('selected');
      $accidentInsurance_time.val($(this).text());
    });

    e.stopPropagation();

  });

  //意外险查看
  $accidentInsurance_Btn.click(function () {
    alert($accidentInsurance_type.val() + ' + ' + $accidentInsurance_time.val());
  });

  /*健康险*/
  var $healthInsurance_type = $('#healthInsurance_type');
  var $healthInsurance_drop_1 = $('#healthInsurance_drop_1');
  var $healthInsurance_product = $('#healthInsurance_product');
  var $healthInsurance_drop_2 = $('#healthInsurance_drop_2');
  var $healthInsurance_Btn = $("#healthInsurance_Btn");

  //默认
  $healthInsurance_type.val($healthInsurance_drop_1.find('.selected').html())
  $healthInsurance_product.val($healthInsurance_drop_2.find('.selected').html())

  //健康险产品
  $healthInsurance_type.click(function (e) {

    if ($healthInsurance_drop_1.is(':hidden')) {
      $healthInsurance_drop_1.show();
      $healthInsurance_drop_2.hide();
    } else {
      $healthInsurance_drop_1.hide();
    }

    $healthInsurance_drop_1.find('li').click(function () {
      $(this).addClass('selected').siblings().removeClass('selected');
      $healthInsurance_type.val($(this).text());
    });

    e.stopPropagation();

  });

  //健康险类型
  $healthInsurance_product.click(function (e) {

    if ($healthInsurance_drop_2.is(':hidden')) {
      $healthInsurance_drop_2.show();
      $healthInsurance_drop_1.hide();
    } else {
      $healthInsurance_drop_2.hide();
    }

    $healthInsurance_drop_2.find('li').click(function () {
      $(this).addClass('selected').siblings().removeClass('selected');
      $healthInsurance_product.val($(this).text());
    });

    e.stopPropagation();

  });

  //健康险查看
  $healthInsurance_Btn.click(function () {
    alert($healthInsurance_type.val() + ' + ' + $healthInsurance_product.val());
  });

  /*旅行险*/
  var $travelInsurance_area = $('#travelInsurance_area');
  var $travelInsurance_drop_1 = $('#travelInsurance_drop_1');
  var $travelInsurance_time = $('#travelInsurance_time');
  var $travelInsurance_drop_2 = $('#travelInsurance_drop_2');
  var $travelInsurance_Btn = $("#travelInsurance_Btn");

  //默认
  $travelInsurance_area.val($travelInsurance_drop_1.find('.selected').html())
  $travelInsurance_time.val($travelInsurance_drop_2.find('.selected').html())

  //旅行险地区
  $travelInsurance_area.click(function (e) {

    if ($travelInsurance_drop_1.is(':hidden')) {
      $travelInsurance_drop_1.show();
      $travelInsurance_drop_2.hide();
    } else {
      $travelInsurance_drop_1.hide();
    }

    $travelInsurance_drop_1.find('li').click(function () {
      $(this).addClass('selected').siblings().removeClass('selected');
      $travelInsurance_area.val($(this).text());
    });

    e.stopPropagation();

  });

  //旅行险时间
  $travelInsurance_time.click(function (e) {

    if ($travelInsurance_drop_2.is(':hidden')) {
      $travelInsurance_drop_2.show();
      $travelInsurance_drop_1.hide();
    } else {
      $travelInsurance_drop_2.hide();
    }

    $travelInsurance_drop_2.find('li').click(function () {
      $(this).addClass('selected').siblings().removeClass('selected');
      $travelInsurance_time.val($(this).text());
    });

    e.stopPropagation();

  });

  //旅行险查看
  $travelInsurance_Btn.click(function () {
    alert($travelInsurance_area.val() + ' + ' + $travelInsurance_time.val());
  });

  /*财产险*/
  var $propertyInsurance_type = $('#propertyInsurance_type');
  var $propertyInsurance_drop = $('#propertyInsurance_drop');
  var $propertyInsurance_Btn = $("#propertyInsurance_Btn");

  //默认
  $propertyInsurance_type.val($propertyInsurance_drop.find('.selected').html())

  //旅行险地区
  $propertyInsurance_type.click(function (e) {

    if ($propertyInsurance_drop.is(':hidden')) {
      $propertyInsurance_drop.show();
    } else {
      $propertyInsurance_drop.hide();
    }

    $propertyInsurance_drop.find('li').click(function () {
      $(this).addClass('selected').siblings().removeClass('selected');
      $propertyInsurance_type.val($(this).text());
    });

    e.stopPropagation();

  });

  //旅行险查看
  $propertyInsurance_Btn.click(function () {
    alert($propertyInsurance_type.val());
  });

  /* conve  点击其他地方消失*/
  $(document).click(function () {
    /*话费充值*/
    $phoneNumberdisplay.hide();
    $phoneNumberLog.hide();
    $phoneDenomLog.hide();
    /*流量充值*/
    $flowNumberdisplay.hide()
    $flowNumberLog.hide();
    $phoneAreaLog.hide();
    $phoneHowManyLog.hide();
    /*固话充值*/
    $fixedlineNumberLog.hide();
    $fixedlineLog.hide();
    $fixedlineAmount.find("span").css('background-position', ' 0 -15px');
    /*宽带充值*/
    $broadbandLog.hide();
    $broadbandArea.find("span").css('background-position', ' 0 -15px');
    $broadbandError.hide();
    $numberError.hide();
    $broadbandNumberLog.hide();
    $broadbandAmountLog.hide();
    $broadbandAmount.find("span").css('background-position', ' 0 -15px');
    /*车险*/
    $carInsurance_drop_1.hide();
    $carInsurance_drop_2.hide();
    $accidentInsurance_drop_1.hide();
    $accidentInsurance_drop_2.hide();
    $healthInsurance_drop_1.hide();
    $healthInsurance_drop_2.hide();
    $travelInsurance_drop_1.hide();
    $travelInsurance_drop_2.hide();
    $propertyInsurance_drop.hide();
  });


  /*滚动事件*/
  var $topWrapBox = $("#topWrapBox");
  var topWrapBoxTop = ($topWrapBox.offset().top + $topWrapBox.outerHeight(true));

  var $fixedtool = $("#fixedtool");
  var $goods = $("#goods");
  var $shop = $("#shop");
  var $quality = $("#quality");
  var $affords = $("#affords");
  var $hotsale = $("#hotsale");
  var $gotop = $("#gotop");
  var $feedback = $("#feedback");
  var $report = $("#report");
  var goodsHb = $('#goodsHb').offset().top - 184;
  var shopHb = $('#shopHb').offset().top - 184;
  var qualityHb = $('#qualityHb').offset().top - 184;
  var affordsHb = $('#affordsHb').offset().top - 184;
  var hotsaleHb = $('#hotsaleHb').offset().top - 184;

  $(document).scroll(function () {

    var scroll = $(this).scrollTop();

    //滚动搜索栏置顶
    if ( scroll >= topWrapBoxTop) {
      $topWrapBox.addClass("roofPlacement");
    } else {
      $topWrapBox.removeClass("roofPlacement");
    }

    //侧边栏位置
    if (scroll >= (600 - $topWrapBox.outerHeight(true))) {
      $fixedtool.css({
        'position': 'fixed',
        'top': '82px'
      });
    } else {
      $fixedtool.css({
        'position': 'absolute',
        'top': '600px'
      });
    }

    //返回底部显示
    if (scroll >= 1000) {
      $gotop.css("display", "block");
    } else {
      $gotop.css("display", "none");
    }

    // //滑动到指定位置高亮显示
    if (scroll >= 0) {
      $goods.addClass("on").siblings().removeClass("on");
    }
    if (scroll >= shopHb) {
      $shop.addClass("on").siblings().removeClass("on");
    }
    if (scroll >= qualityHb) {
      $quality.addClass("on").siblings().removeClass("on");
    }
    if (scroll >= affordsHb) {
      $affords.addClass("on").siblings().removeClass("on");
    }
    if (scroll >= hotsaleHb) {
      $hotsale.addClass("on").siblings().removeClass("on");
    }

  });

  //点击事件,定位到该位置
  $goods.click(function () {
    $('html,body').stop().animate({  scrollTop: goodsHb   }, 600);
    $(this).addClass("on").siblings().removeClass("on");
  });

  $shop.click(function () {
    $('html,body').stop().animate({  scrollTop: shopHb  }, 600);
    $(this).addClass("on").siblings().removeClass("on");
  });

  $quality.click(function () {
    $('html,body').stop().animate({  scrollTop: qualityHb  }, 600);
    $(this).addClass("on").siblings().removeClass("on");
  });

  $affords.click(function () {
    $('html,body').stop().animate({  scrollTop: affordsHb  }, 600);
    $(this).addClass("on").siblings().removeClass("on");
  });

  $hotsale.click(function () {
    $('html,body').stop().animate({  scrollTop: hotsaleHb  }, 600);
    $(this).addClass("on").siblings().removeClass("on");
  });

  $gotop.click(function () {
    $('html,body').stop().animate({  scrollTop: 0  }, 1000);
  });

  $feedback.click(function () {
    alert('这是：' + $(this).html());
  });
  
  $report.click(function () {
    alert('这是：' + $(this).html());
  });

  /*
    运动函数
      构造函数，整个页面的轮播都可以用，
      Frame（要滚动的对象，标点，最大页数（标点的个数），滚动距离，滚动时间（定时器用））
    使用：声明一个变量把函数new给它，在用这个变量调用。
      var tmall = new Frame($tmallImg, $tmallLi, tmallNum, tmallWidth, 4000);
  */
  function Frame(box, dot, num, width, time) {
    this.box = box;
    this.dot = dot;
    this.num = num;
    this.width = width;
    this.time = time;
    this.index = 0;
    this.counter = null;
    //下一页
    this.next = function () {
      this.index++;
      if (this.index > this.num) {
        this.box.css({
          left: 0
        });
        this.index = 1;
      }
      this.core();
    };
    //上一页
    this.prev = function () {
      this.index--;
      if (this.index < 0) {
        this.box.css({
          left: this.num * (-this.width)
        });
        this.index = this.num - 1;
      }
      this.core();
    };
    //核心
    this.core = function () {
      this.box.stop(true); //防止jq动画连续点击
      this.dot.eq(this.index > this.num - 1 ? 0 : this.index).addClass('selected').siblings().removeClass('selected'); //标点
      this.box.animate({
        left: this.index * (-this.width)
      }); //滚动
    };
    //自动轮播
    this.autoMove = function (who) {
      this.counter = setInterval(function () {
        who.next();
      }, this.time);
    };
    //当前页监听
    this.currentPage = function (master, currentPage) {
      setInterval(function () {
        if (master.index == 6) {
          currentPage.html(1);
        } else {
          currentPage.html(master.index + 1);
        }
      }, 100)
    }
  };

  //向上滚动函数
  function upward(box, num, height, time) {
    this.box = box;
    this.num = num;
    this.height = height;
    this.time = time;
    this.index = 0;
    this.counter = null;
    //核心
    this.core = function () {
      this.index++;
      if (this.index > this.num - 1) {
        this.box.css({
          top: -this.height
        });
        this.index = 0;
      }
      this.box.animate({
        top: this.index * (-this.height)
      }); //滚动
    }
    this.autoMove = function (who) {
      this.counter = setInterval(function () {
        who.core();
      }, this.time);
    }
  };
});